import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import s from './s';
import init from '@feidao/web/framework/browser/dn/component';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import fire_component_msg from '@feidao/web/atom/browser/fsm/fire-component-msg';

const feidao = {}, serverip = 'http://192.168.40.195/fsweb/getfile?productid=flippedclass&id=';
let pics: object[] = [], img: HTMLImageElement = null, curr_i: number, btn_l: HTMLElement = null, btn_r: HTMLElement = null;
const daoke = {
	async ec01(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-reality-picture-003 init b ec01 init', args);
		const pic = args[0][1];
		img = fd.data.node.querySelector('[data-feidao-id="pic"]') as HTMLImageElement;
		img.src = serverip + pic;
		const idx = parseInt(args[0][0]);
		const c = args[0][2];
		pics = await nodejs("flippedclass", "class_room_picture_find", c);
		console.log(pics);
		btn_l = fd.data.node.querySelector('[data-feidao-id="btn_l"]');
		btn_r = fd.data.node.querySelector('[data-feidao-id="btn_r"]');
		curr_i = idx;
		fd.data.node.classList.remove('display-n');
	},
	async eu02(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-reality-picture-003 init b eu02 click left', args);
		if (curr_i == 0) {
			alert("已经是第一张了");
			return;
		}
		curr_i--;
		img.src = serverip + pics[curr_i]['pic_path'];
	},
	async eu03(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-reality-picture-003 init b eu03 click right', args);
		if (curr_i == pics.length - 1) {
			alert("已经是最后一张了");
			return;
		}
		curr_i++;
		img.src = serverip + pics[curr_i]['pic_path'];
	},
	async eu04(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-reality-picture-003 init b eu03 click close', args);
		fd.data.node.classList.add('display-n');
	}
};

const rules = {};

export default function main(url: string, query: any) {
	return init('zj-reality-picture-003', s, rules, feidao, daoke, url, query, { spaceid: 'flippedclass', systemid: '5991', refsystemid: '@refsystemid' });
}
